<template>
	<view class="detail">
		<template v-if="isLoad === true">
			<my-head :head="head" />
			<tab-bar />
			<list :replies="replies" :topics="topics" />
		</template>
	</view>
</template>

<script>
	import head from '@/components/head'
	import tabBar from './tab-bar.vue'
	import list from './list.vue'
	export default {
		components: {
			'my-head': head,
			'tab-bar': tabBar,
			list
		},
		data (){
			return {
				isLoad: false,
				head: {},
				replies: [],
				topics: []
			}
		},
		onLoad (params){
			this.getAuthorDetail(params.author)
		},
		methods: {
			async getAuthorDetail (author){
				uni.showLoading({
					title: '加载中...'
				})
				let result = await this.$request.get('/user/'+author)
				let { data } = result
				if(result.success){
					this.head = {
						avatar_url: data['avatar_url'],
						score: data['score'],
						loginname: data['loginname'],
						create_at: data['create_at']
					};
					this.replies = data['recent_replies']
					this.topics = data['recent_topics']
				}
				this.isLoad = true
				uni.hideLoading()
			}
		}
	}
</script>
